package com.sky.controller.admin;

import com.sky.constant.RedisConstant;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "管理端店铺相关")
@Slf4j
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;

    @ApiOperation("设置店铺状态")
    //路径参数使用@PathVariable注解
    @PutMapping("/{status}")
    public Result<String> setShopStatus(@PathVariable("status") Integer status){
        redisTemplate.opsForValue().set(RedisConstant.SHOP_STATUS_KEY,status);
        return Result.success();
    }

    @ApiOperation("获取店铺状态")
    @GetMapping("/status")
    public Result<Integer> getShopStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(RedisConstant.SHOP_STATUS_KEY);
        if(status == null){
            //考虑到第一次的情况
            status = 0;
        }
        return Result.success(status);
    }
}
